include $(RT28xx_DIR)/os/linux/config.mk

obj_wsc :=
obj_vht :=
obj_cmm := \
	../../common/crypt_md5.o \
	../../common/crypt_sha2.o \
	../../common/crypt_hmac.o \
	../../common/crypt_aes.o \
	../../common/crypt_arc4.o \
	../../common/mlme.o \
	../../common/cmm_wep.o \
	../../common/action.o \
	../../common/cmm_data.o \
	../../common/rtmp_init.o \
	../../common/rtmp_init_inf.o \
	../../common/cmm_tkip.o \
	../../common/cmm_aes.o \
	../../common/cmm_sync.o \
	../../common/eeprom.o \
	../../common/cmm_sanity.o \
	../../common/cmm_info.o \
	../../common/cmm_cfg.o \
	../../common/cmm_wpa.o \
	../../common/cmm_radar.o \
	../../common/spectrum.o \
	../../common/rtmp_timer.o \
	../../common/rt_channel.o \
	../../common/cmm_profile.o \
	../../common/cmm_asic.o \
	../../common/scan.o \
	../../common/cmm_cmd.o \
	../../common/uapsd.o \
	../../common/ps.o \
	../../rate_ctrl/ra_ctrl.o \
	../../rate_ctrl/alg_legacy.o \
	../../rate_ctrl/alg_ags.o \
	../../chips/rtmp_chip.o \
	../../common/txpower.o \
	../../mac/rtmp_mac.o \
	../../mgmt/mgmt_hw.o \
	../../mgmt/mgmt_entrytb.o \
	../../phy/rtmp_phy.o \
	../../phy/rlt_phy.o \
	../../phy/rlt_rf.o

ifeq ($(HAS_BLOCK_NET_IF),y)
obj_cmm += ../../common/netif_block.o
endif

ifeq ($(HAS_NEW_RATE_ADAPT_SUPPORT),y)
obj_cmm += ../../rate_ctrl/alg_grp.o
endif

ifeq ($(HAS_RATE_ADAPT_AGS_SUPPORT),y)
obj_cmm += ../../rate_ctrl/alg_ags.o
endif

ifeq ($(HAS_DFS_SUPPORT),y)
obj_cmm += ../../common/cmm_dfs.o
endif

ifeq ($(HAS_CS_SUPPORT),y)
obj_cmm += ../../common/cmm_cs.o
endif

#ifdef DOT11_N_SUPPORT
ifeq ($(HAS_DOT11_N_SUPPORT),y)
obj_cmm += \
	../../common/ba_action.o \
	../../mgmt/mgmt_ht.o

#ifdef TXBF_SUPPORT
ifeq ($(HAS_TXBF_SUPPORT),y)
obj_cmm += \
	../../common/cmm_txbf.o \
	../../common/cmm_txbf_cal.o
endif
#endif // TXBF_SUPPORT //
endif
#endif // DOT11_N_SUPPORT //

#ifdef DOT11_VHT_SUPPORT
ifeq ($(HAS_DOT11_VHT_SUPPORT),y)
obj_vht += \
	../../mgmt/mgmt_vht.o \
	../../common/vht.o
endif
#endif // DOT11_VHT_SUPPORT //

#ifdef WSC_INCLUDED
ifeq ($(HAS_WSC),y)
obj_wsc += \
	../../common/wsc.o \
	../../common/wsc_tlv.o \
	../../common/crypt_biginteger.o \
	../../common/crypt_dh.o
endif
ifeq ($(HAS_WSC_V2),y)
obj_wsc += ../../common/wsc_v2.o
endif
#endif // WSC_INCLUDED //

#ifdef ANDES_FIRMWARE_SUPPORT
ifeq ($(HAS_ANDES_FIRMWARE_SUPPORT),y)
obj_cmm += ../../mcu/rtmp_and.o
endif
#endif /* ANDES_FIRMWARE_SUPPORT */

#ifdef CONFIG_AP_SUPPORT
ifeq ($(RT28xx_MODE),AP)
ifneq ($(findstring 7601,$(CHIPSET)),)
MOD_NAME = mt$(MODULE)ap
else
MOD_NAME = rt$(MODULE)ap
endif
DAT_PATH = /etc/wifi/RT$(CHIPSET_DAT)AP
DAT_FILE_NAME = RT$(CHIPSET_DAT)AP.txt
endif
#endif // CONFIG_AP_SUPPORT //

LINUX_VER = $(shell uname -r)

obj-m := $(MOD_NAME).o

#ifdef CONFIG_AP_SUPPORT
ifeq ($(RT28xx_MODE),AP)
$(MOD_NAME)-objs := \
	../../os/linux/rt_profile.o \
	../../ap/ap_mbss.o \
	../../ap/ap.o \
	../../ap/ap_assoc.o \
	../../ap/ap_auth.o \
	../../ap/ap_connect.o \
	../../ap/ap_mlme.o \
	../../ap/ap_sanity.o \
	../../ap/ap_sync.o \
	../../ap/ap_wpa.o \
	../../ap/ap_data.o \
	../../ap/ap_autoChSel.o \
	../../ap/ap_qload.o \
	../../ap/ap_cfg.o \
	$(obj_vht) \
	$(obj_cmm) \
	$(obj_wsc)

#ifdef WSC_INCLUDED
ifeq ($(HAS_WSC),y)
$(MOD_NAME)-objs += \
	../../common/wsc_ufd.o
endif
#endif // WSC_INCLUDE //
	
ifeq ($(HAS_ATE),y)
$(MOD_NAME)-objs += ../../ate/common/rt_ate.o
endif

ifeq ($(HAS_QA_SUPPORT),y)
$(MOD_NAME)-objs += ../../ate/common/rt_qa.o
endif

ifeq ($(OSABL),NO)
$(MOD_NAME)-objs += \
	../../ap/ap_mbss_inf.o \
	../../common/rt_os_util.o \
	../../os/linux/ap_ioctl.o \
	../../os/linux/rt_linux.o \
	../../os/linux/rt_main_dev.o
else
$(MOD_NAME)-objs += \
	../../os/linux/rt_symb.o
endif

#ifdef BG_FT_SUPPORT
ifeq ($(OSABL),NO)
ifeq ($(HAS_BGFP_SUPPORT),y)
$(MOD_NAME)-objs += \
	../../os/linux/br_ftph.o
endif
endif
#endif // BG_FT_SUPPORT //


#ifdef CRDA_SUPPORT
ifeq ($(OSABL),NO)
ifeq ($(HAS_CFG80211_SUPPORT),y)
$(MOD_NAME)-objs += \
	../../os/linux/cfg80211.o \
	../../os/linux/cfg80211drv.o
endif
endif

ifeq ($(OSABL),YES)
ifeq ($(HAS_CFG80211_SUPPORT),y)
$(MOD_NAME)-objs += \
	../../os/linux/cfg80211drv.o
endif
endif
#endif // CRDA_SUPPORT //

#ifdef LED_CONTROL_SUPPORT
ifeq ($(HAS_LED_CONTROL_SUPPORT),y)
$(MOD_NAME)-objs += \
	../../common/rt_led.o
endif
#endif // LED_CONTROL_SUPPORT //

ifeq ($(HAS_RT2880_RT2860_COEXIST),y)	
RT28XX_AP_OBJ += \
	../../os/linux/rt_pci_rbus.o \
	../../os/linux/rt_rbus_pci_util.o \
	../../os/linux/pci_main_dev.o \
	../../common/dfs.o
endif

ifeq ($(HAS_WDS),y)
$(MOD_NAME)-objs += ../../ap/ap_wds.o

ifeq ($(OSABL),NO)
$(MOD_NAME)-objs += \
	../../ap/ap_wds_inf.o
endif
endif

#ifdef APCLI_SUPPORT
ifeq ($(HAS_APCLI),y)
$(MOD_NAME)-objs += \
	../../ap/ap_apcli.o \
	../../ap/apcli_ctrl.o \
	../../ap/apcli_sync.o \
	../../ap/apcli_auth.o \
	../../ap/apcli_assoc.o \
	../../common/cmm_mat.o \
	../../common/cmm_mat_iparp.o \
	../../common/cmm_mat_pppoe.o \
	../../common/cmm_mat_ipv6.o

ifeq ($(OSABL),NO)
$(MOD_NAME)-objs += \
	../../ap/ap_apcli_inf.o
endif
endif
#endif // APCLI_SUPPORT //

ifeq ($(HAS_IGMP_SNOOP_SUPPORT),y)
$(MOD_NAME)-objs += ../../common/igmp_snoop.o
endif

ifeq ($(HAS_QOS_DLS_SUPPORT),y)
$(MOD_NAME)-objs += ../../ap/ap_dls.o
endif

ifeq ($(HAS_IDS_SUPPORT),y)
$(MOD_NAME)-objs += ../../ap/ap_ids.o
endif

ifeq ($(PLATFORM),IKANOS_V160)
$(MOD_NAME)-objs += ../../os/linux/vr_ikans.o
endif

ifeq ($(PLATFORM),IKANOS_V180)
$(MOD_NAME)-objs += ../../os/linux/vr_ikans.o
endif

ifeq ($(PLATFORM),BL2348)
ifeq ($(OSABL),NO)
$(MOD_NAME)-objs += ../../os/linux/vr_bdlt.o
endif
endif
#ifdef PLATFORM_BL23570
ifeq ($(PLATFORM),BL23570)
rt$(CHIPSET)ap-objs += \
	../../os/linux/vr_bdlt.o
endif
#endif // PLATFORM_BL23570 //

#ifdef WAPI_SUPPORT
ifeq ($(HAS_WAPI_SUPPORT),y)
$(MOD_NAME)-objs += \
	../../common/wapi.o
endif
#endif // WAPI_SUPPORT //

ifeq ($(HAS_CLIENT_WDS_SUPPORT),y)
$(MOD_NAME)-objs += \
	../../common/client_wds.o
endif

ifeq ($(HAS_EASY_CONFIG_SETUP_SUPPORT),y)
ifeq ($(PLATFORM),RALINK_3052)
$(MOD_NAME)-objs += lib.a
endif
endif

endif
#endif // CONFIG_AP_SUPPORT //

#chip releated

#ifdef RT3290
ifneq ($(findstring 3290,$(CHIPSET)),)
$(MOD_NAME)-objs += \
	../../common/cmm_mac_pci.o \
	../../common/cmm_data_pci.o \
	../../os/linux/rt_rbus_pci_drv.o \
	../../common/rtmp_mcu.o \
	../../common/ee_prom.o \
	../../common/ee_efuse.o \
	../../common/rt_rf.o \
	../../chips/rt30xx.o \
	../../chips/rt3290.o

ifeq ($(OSABL),NO)
$(MOD_NAME)-objs += \
	../../os/linux/rt_pci_rbus.o\
	../../os/linux/rt_rbus_pci_util.o\
	../../os/linux/pci_main_dev.o
endif

ifneq ($(findstring $(RT28xx_MODE),STA APSTA),)
$(MOD_NAME)-objs += \
	../../common/frq_cal.o
endif

endif
#endif // RT3290 //

#ifdef RT6592
ifneq ($(findstring 6592,$(CHIPSET)),)
$(MOD_NAME)-objs += \
	../../common/cmm_mac_pci.o \
	../../common/cmm_data_pci.o \
	../../os/linux/rt_rbus_pci_drv.o \
	../../common/rtmp_mcu.o \
	../../common/ee_prom.o \
	../../common/ee_efuse.o \
	../../common/rt_rf.o \
	../../chips/rt6592.o

ifeq ($(OSABL),NO)
$(MOD_NAME)-objs += \
	../../os/linux/rt_pci_rbus.o \
	../../os/linux/rt_rbus_pci_util.o \
	../../os/linux/pci_main_dev.o
endif
endif
#endif // RT6592 //

#ifdef RT6590
ifneq ($(findstring 6590,$(CHIPSET)),)
$(MOD_NAME)-objs += \
	../../common/cmm_mac_pci.o \
	../../common/cmm_data_pci.o \
	../../os/linux/rt_rbus_pci_drv.o \
	../../common/ee_efuse.o \
	../../common/ee_prom.o \
	../../common/rt_rf.o \
	../../chips/rt30xx.o \
	../../chips/rt65xx.o \
	../../chips/rt6590.o \
	../../mac/ral_nmac.o \
	../../mcu/rtmp_and.o

ifeq ($(HAS_RTMP_FLASH_SUPPORT),y)
$(MOD_NAME)-objs += \
	../../common/ee_flash.o
endif

ifeq ($(OSABL),NO)
$(MOD_NAME)-objs += \
	../../os/linux/rt_pci_rbus.o \
	../../os/linux/rt_rbus_pci_util.o \
	../../os/linux/pci_main_dev.o
endif

ifneq ($(findstring $(RT28xx_MODE),STA APSTA),)
$(MOD_NAME)-objs += \
	../../common/frq_cal.o
endif

endif
#endif // RT6590 //

#ifdef RT6570
ifneq ($(findstring 6570,$(CHIPSET)),)
$(MOD_NAME)-objs += \
	../../common/cmm_mac_usb.o \
	../../common/cmm_data_usb.o \
	../../common/rtusb_io.o \
	../../common/rtusb_data.o \
	../../common/rtusb_bulk.o \
	../../os/linux/rt_usb.o \
	../../common/ee_prom.o \
	../../common/ee_efuse.o \
	../../common/rtmp_mcu.o \
	../../common/rt_rf.o \
	../../chips/rt30xx.o \
	../../chips/rt65xx.o \
	../../chips/rt6590.o \
	../../mac/ral_nmac.o \
	../../mcu/rtmp_and.o

ifeq ($(HAS_RTMP_FLASH_SUPPORT),y)
$(MOD_NAME)-objs += \
	../../common/ee_flash.o
endif

ifeq ($(HAS_TSO_SUPPORT),y)
$(MOD_NAME)-objs += \
	../../naf/net_acc.o \
	../../naf/tso.o \
	../../naf/cso.o
endif

ifeq ($(OSABL),NO)
$(MOD_NAME)-objs += \
	../../os/linux/rt_usb.o \
	../../os/linux/rt_usb_util.o \
	../../os/linux/usb_main_dev.o \
	../../common/rtusb_dev_id.o
endif

ifneq ($(findstring $(RT28xx_MODE),STA APSTA),)
$(MOD_NAME)-objs += \
	../../common/frq_cal.o
endif

endif
#endif // RT6570 //

#ifdef RT8592
ifneq ($(findstring 8592,$(CHIPSET)),)
$(MOD_NAME)-objs += \
	../../common/cmm_mac_pci.o \
	../../common/cmm_data_pci.o \
	../../os/linux/rt_rbus_pci_drv.o \
	../../common/ee_prom.o \
	../../common/ee_efuse.o \
	../../common/rtmp_mcu.o \
	../../common/rt_rf.o \
	../../chips/rt30xx.o \
	../../chips/rt65xx.o \
	../../chips/rt6592.o \
	../../chips/rt85592.o \
	../../mac/ral_nmac.o \
	../../mcu/rtmp_and.o

ifeq ($(HAS_RTMP_FLASH_SUPPORT),y)
$(MOD_NAME)-objs += \
	../../common/ee_flash.o
endif

ifeq ($(OSABL),NO)
$(MOD_NAME)-objs += \
	../../os/linux/rt_pci_rbus.o \
	../../os/linux/rt_rbus_pci_util.o \
	../../os/linux/pci_main_dev.o
endif

ifneq ($(findstring $(RT28xx_MODE),STA APSTA),)
$(MOD_NAME)-objs += \
	../../common/frq_cal.o
endif

endif
#endif // RT8592 //

#ifdef MT7601E
ifneq ($(findstring 7601E,$(CHIPSET)),)
$(MOD_NAME)-objs += \
	../../common/cmm_mac_pci.o \
	../../common/cmm_data_pci.o \
	../../os/linux/rt_rbus_pci_drv.o \
	../../common/ee_prom.o \
	../../common/ee_efuse.o \
	../../mcu/rtmp_and.o \
	../../mcu/rtmp_mcu.o \
	../../mcu/rtmp_M51.o \
	../../common/rt_rf.o \
	../../chips/rt30xx.o \
	../../chips/mt7601.o \
	../../mac/ral_omac.o

ifeq ($(HAS_RTMP_FLASH_SUPPORT),y)
$(MOD_NAME)-objs += \
	../../common/ee_flash.o
endif

ifeq ($(HAS_ATE),y)
$(MOD_NAME)-objs += \
	../../ate/chips/mt7601_ate.o \
	../../ate/common/ate_usb.o
endif

ifeq ($(OSABL),NO)
$(MOD_NAME)-objs += \
	../../os/linux/rt_pci_rbus.o \
	../../os/linux/rt_rbus_pci_util.o \
	../../os/linux/pci_main_dev.o
endif

ifneq ($(findstring $(RT28xx_MODE),STA APSTA),)
$(MOD_NAME)-objs += \
	../../common/frq_cal.o
endif

endif
#endif // MT7601E //

#ifdef MT7601U
ifneq ($(findstring 7601U,$(CHIPSET)),)
$(MOD_NAME)-objs += \
	../../common/cmm_mac_usb.o \
	../../common/cmm_data_usb.o \
	../../common/rtusb_io.o \
	../../common/rtusb_data.o \
	../../common/rtusb_bulk.o \
	../../os/linux/rt_usb.o \
	../../common/ee_prom.o \
	../../common/ee_efuse.o \
	../../mcu/rtmp_and.o \
	../../mcu/rtmp_mcu.o \
	../../mcu/rtmp_M51.o \
	../../common/rt_rf.o \
	../../chips/mt7601.o \
	../../mac/ral_omac.o

ifeq ($(HAS_RTMP_FLASH_SUPPORT),y)
$(MOD_NAME)-objs += \
	../../common/ee_flash.o
endif

ifeq ($(HAS_ATE),y)
$(MOD_NAME)-objs += \
	../../ate/chips/mt7601_ate.o \
	../../ate/common/ate_usb.o
endif

ifeq ($(HAS_TSO_SUPPORT),y)
$(MOD_NAME)-objs += \
	../../naf/net_acc.o \
	../../naf/tso.o \
	../../naf/cso.o
endif

ifeq ($(OSABL),NO)
$(MOD_NAME)-objs += \
	../../os/linux/rt_usb.o \
	../../os/linux/rt_usb_util.o \
	../../os/linux/usb_main_dev.o \
	../../common/rtusb_dev_id.o
endif

ifneq ($(findstring $(RT28xx_MODE),STA APSTA),)
$(MOD_NAME)-objs += \
	../../common/frq_cal.o
endif

endif
#endif // MT7601U //

PHONY := clean install uninstall

clean:
	@rm -f ../../common/*.o
	@rm -f ../../common/.*.{cmd,flags,d}
	@rm -f ../../os/linux/*.{o,ko,mod.{o,c}}
	@rm -f ../../os/linux/.*.{cmd,flags,d}
	@rm -fr ../../os/linux/.tmp_versions
#Must clean Module.symvers; or you will suffer symbol version not match
#when OS_ABL = YES.
	@rm -f ../../os/linux/Module.symvers
	@rm -f ../../os/linux/Modules.symvers
	@rm -f ../../os/linux/Module.markers
	@rm -f ../../os/linux/modules.order
	@rm -f ../../chips/*.o
	@rm -f ../../chips/.*.{cmd,flags,d}
ifeq ($(RT28xx_MODE),AP)
	@rm -f ../../ap/*.o
	@rm -f ../../ap/.*.{cmd,flags,d}
else
ifeq ($(RT28xx_MODE),STA)
	@rm -f ../../sta/*.o
	@rm -f ../../sta/.*.{cmd,flags,d}
else
ifeq ($(RT28xx_MODE),APSTA)
	@rm -f ../../ap/*.o
	@rm -f ../../ap/.*.{cmd,flags,d}
	@rm -f ../../sta/*.o
	@rm -f ../../sta/.*.{cmd,flags,d}
endif
endif
endif

strip:
	$(STRIP) --strip-unneeded --strip-debug $(MOD_NAME).ko

install:
	mkdir -p $(DAT_PATH)
	cp $(RT28xx_DIR)/$(DAT_FILE_NAME) $(DAT_PATH)/
	install -m 644 -c $(MOD_NAME).ko $(LINUX_SRC_MODULE)/
	depmod $(LINUX_VER)

uninstall:
	rm -f $(LINUX_SRC_MODULE)/$(MOD_NAME).ko
	depmod $(LINUX_VER)

# Declare the contents of the .PHONY variable as phony.  We keep that
# information in a variable so we can use it in if_changed and friends.
.PHONY: $(PHONY)
